//
//  EncryptRequestAction.m
//  FinancialStore
//
//  Created by zhenqiu on 16/7/19.
//  Copyright © 2016年 zhenqiu. All rights reserved.
//

#import "EncryptRequestAction.h"

@implementation EncryptRequestAction

-(instancetype)init{
    
    if (self = [super init]) {
        // to do
    }
    return self;
    
}


+(id)encryptParameter:(id)parameter{
    
    if(!parameter){
        
        return nil;
    }
    
    NSMutableDictionary * dic = [NSMutableDictionary dictionaryWithCapacity:1];
    NSError * error = nil;
    NSData * jsonData = [NSJSONSerialization dataWithJSONObject:parameter options:0 error:&error];
    NSString * jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSString * authKey = [self getAuthKey];
    NSString * encryptStr = [AES128Base64Util AES128Encrypt:jsonStr withKey:authKey withIV:(NSString *)AUTH_IV];
    [dic setValue:encryptStr forKey:HTTP_BODY_KEY];
    return dic;
}

+(id)encryptStr:(id)str{
    
    NSString *encryptStr = @"";
    if(str && [str length] > 0){
        
        NSString * authKey = [self getAuthKey];
        encryptStr = [AES128Base64Util AES128Encrypt:str withKey:authKey withIV:(NSString *)AUTH_IV];
    }
    
    return encryptStr;
    
}

@end
